package main.resources.controller.command.chat;

import main.resources.controller.command.Command;
import main.resources.controller.dao.moodle.MdlChatDao;
import main.resources.controller.dao.moodle.MdlContextDao;
import main.resources.controller.dao.moodle.MdlCourseSectionDao;
import main.resources.exceptions.DaoException;
import main.resources.model.Fabrica;
import main.resources.model.entity.moodle.MdlChat;
import main.resources.model.entity.moodle.MdlContext;
import main.resources.model.entity.moodle.MdlCourseSection;
import main.resources.useful.Useful;

public class ChatIncludeCommand implements Command {

	private MdlChat chat;	
	
	public ChatIncludeCommand(MdlChat chat) {
		this.chat = chat;
	}

	@Override
	public void execute() throws DaoException {
		MdlChatDao.getInstance().include(chat);
		MdlContext context = Fabrica.criarContexto("70");
		MdlContextDao.getInstance().include(context);		
		MdlCourseSection section = MdlCourseSectionDao.getInstance().filterByCourse(chat.getCourse()).get(0);
		section.setSequence(Useful.generateSequence(section.getSequence(), context.getInstanceid().toString()));
		MdlCourseSectionDao.getInstance().edit(section);
	}

}
